package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaFile;
import com.sailfish.springbootdemo.service.db1.PcbaFileService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/pcbaFile")
public class PcbaFileController {

    @Autowired
    private PcbaFileService pcbaFileService;

    @PostMapping("/getPcbaFileGroupByResourceId")
    public Result getPcbaFileGroupByResourceId(Integer pcbaDeviceResourceId) {
        try {
            if (pcbaDeviceResourceId == null || "".equals(pcbaDeviceResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceResourceId", "Miss Param pcbaDeviceResourceId", null);
            }
            List<String> pcbaFileGroupByResourceId = pcbaFileService.getPcbaFileGroupByResourceId(pcbaDeviceResourceId);
            return ResultUtil.success(pcbaFileGroupByResourceId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/getAllPcbaFileByStatus")
    public Result getAllPcbaFileByStatus(Integer status, Integer pcbaCompanyId, String searchFileName) {
        try {
            return ResultUtil.success(pcbaFileService.getAllPcbaFileByStatus(status, pcbaCompanyId, searchFileName));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/addPcbaFile")
    public Result addPcbaFile(PcbaFile pcbaFile) {
        return pcbaFileService.addPcbaFile(pcbaFile);
    }

    @PostMapping("/deletePcbaFile")
    public Result deletePcbaFile(Integer pcbaFileId) {
        return pcbaFileService.deletePcbaFile(pcbaFileId);
    }

    @PostMapping("/updatePcbaFileStatus")
    public Result updatePcbaFileStatus(Integer status, String notes, Integer pcbaFileId) {
        return pcbaFileService.updatePcbaFileStatus(status, notes, pcbaFileId);
    }

    @PostMapping("/updatePcbaFile")
    public Result updatePcbaFile(PcbaFile pcbaFile) {
        return pcbaFileService.updatePcbaFile(pcbaFile);
    }

    @PostMapping("/updatePcbaFileRelatedPcbaDeviceResource")
    public Result updatePcbaFileRelatedPcbaDeviceResource(Integer pcbaDeviceResourceId, Integer fileGroupId, Integer pcbaFileId) {
        return pcbaFileService.updatePcbaFileRelatedPcbaDeviceResource(pcbaDeviceResourceId, fileGroupId, pcbaFileId);
    }
}
